<?php

include 'proftarget.php';
//include file for profession target calculation

//function to handle empty attributes
function xml_blank($name, $index, $attr)
{
	if (!$name[$index])
		{return 'None';}
	else
	{
		return $name[$index][$attr];
	}
}

//function with replace to handle empty item attributes
function item($name, $index, $attr, $return)
{
	if (!$name[$index])
		{return $return;}
	else
		{return $name[$index][$attr];}
}


//funtion to build item images
function img_build($name, $index)
{
	if (!$name[$index]['icon'])
		{return "<img class='char item' src='blank.gif'/>";}
	else
	{
		$imgurl = $name[$index]['icon'];
		$class = "char qi".$name[$index]['quality'];
		return "<img class='$class' src='http://us.media.blizzard.com/wow/icons/56/$imgurl.jpg'/>";
	}
}

//function to create html for an item using the 'url' field
//the 'class' value can be used to return a colour for item quality q0,q1 etc.
function item_img($url,$class='',$title='',$itemId)
{
if (empty($itemId))
{return '<img title="'.$title.'" class="'.$class.'" src="http://us.media.blizzard.com/wow/icons/56/'.$url.'.jpg"/>';}
else
{return '<a target="_blank" rel="item='.$itemId.'" href="http://www.wowhead.com/item='.$itemId.'"><img title="'.$title.'" class="'.$class.'" src="http://us.media.blizzard.com/wow/icons/56/'.$url.'.jpg"/></a>';}
}

function wowhead()

{
"<a target='_blank' class='wowhead' href='http://www.wowhead.com/item=".$characterItems['chest']['id']."' rel='item=".$characterItems['chest']['id']."'>".img_build($characterItems,'chest')."</a>";
}


//function to build table rows
function build_row($name, $stat, $op, $per, $title)
{
	if ($stat > 0)
		{return "<tr>" . "<td title='" . $title . "'>" . $name . "</td><td>" . $op . $stat . $per . "</td></tr>";}
	else
		{return '';}
}

//function to build table top rows
//added javascript to show/hide sections
function build_row_hi($name, $stat, $op, $items, $title, $section)
{
	if ($stat > 0||$stat=='')
		if (($items <> '')&&($items > 0))
			//  {return "<tr class='highlight'>" . "<td title='" . $title . "'>" . $name . "</td><td>" . $op .
			//   onMouseOut=\"displayRow('none','" . $section . "')\"
			{return "<tr class='highlight' onMouseOver=\"displayRow('','" . $section . "')\">" . "<td title='" . $title . "'>" . $name . "</td><td>" . $op .
				$stat . " (+" . $items . " from items)" . "</td></tr>";}
	else if ($items == '')
			//  {return "<tr class='highlight'>" . "<td title='" . $title . "'>" . $name . "</td><td>" . $op . $stat . "</td></tr>";}
			{return "<tr class='highlight' onMouseOver=\"displayRow('','" . $section . "')\">" . "<td title='" . $title . "'>" . $name . "</td><td>" . $op . $stat . "</td></tr>";}
	else
		{return '';}
}

/**
 * Implode an array with the key and value pair giving
 * a glue, a separator between pairs and the array
 * to implode.
 * @param string $glue The glue between key and value
 * @param string $separator Separator between pairs
 * @param array $array The array to implode
 * @return string The imploded array
 */
function array_implode( $glue, $separator, $array ) {
	if ( ! is_array( $array ) ) return $array;
	$string = array();
	foreach ( $array as $key => $val ) {
		if ( is_array( $val ) )
			$val = implode( ',', $val );
		$string[] = "{$key}{$glue}{$val}";

	}
	return implode( $separator, $string );

}

function roundLevel($level)//function to get nearest level - returns 60 for level 69 etc.
{
if ($level<85)//hard coded, must be changed on expansion
{
$level = $level/10;//convert to a decimal
$level = floor($level);//round down
$level = $level*10;//convert back to integer
}
return $level;
}

function hitCap($level, $hitRating)
{
	$baseMiss = 0.05;//base miss % single wield/special attack
	$baseMissDual = 0.24;//base miss % dual wield
	$level = roundLevel($level);
	/* The chance to hit now increases by 1% per 120.125  at 85, 30.7548 hit rating points at level 80, 14.7905 hit rating points at level 70, and 9.3793 hit rating points at level 60. The base chance to miss against an opponent of equal level is 5% for single wield and 24% for dual wield.
//special attacks count as single wield
*/
	if ($level==85)
		{$constant=120.125;}
	else if ($level==80)
			{$constant=30.7548;}
	else if ($level==70)
			{$constant=14.7905;}
	else if ($level==60)
			{$constant=9.3793;}
	else if ($level<60)
			{$constant=0;}

	if ($constant>0)
		{$singleHitCap = 5*$constant;//approximations of hit cap required
		$singleHitCapRaid = 8*$constant;
		$dualHitCap = 24*$constant;
		$dualHitCapRaid = 27*$constant;

		$capArray = array($singleHitCap,$singleHitCapRaid,$dualHitCap,$dualHitCapRaid);

		foreach ($capArray as $cap)
		{
			if ($cap < $hitRating)//compare hit cap to actual hit rating
				{$return[] = 1;}//return one if capped
			else
				{$return[] = 0;}
		}
		foreach ($capArray as $val)
		{
		$return[]=$val;//add the actual hit ratings to the end of the array
		}
		
		
	}
	return $return;
}


?>
